import React from "react";
import { inject, observer } from "mobx-react";
import FormDesigner from "./form";
import PathDesigner from './path';
import AppDesignerHeader from "./header";
import EdcExcel from "./excel";
import AnalysisDesigner from "./analysis";
import EdcData from "./data";
import renderNoRight from "../../utils/renderNoRight";

@inject('edcAppDesignerStore')
@observer
export default class AppDesigner extends React.Component {
  constructor(props) {
    super();
    this.store = props.edcAppDesignerStore;
  }
  componentDidMount() {
    this.store.initDesigner(this.props.params);
  }

  render() {
    if (this.store.noRight) {
      return renderNoRight();
    }
    return (
      <div className='wea-edc-container wea-edc-app-designer'>
        <AppDesignerHeader
          store={this.store}
        />
        <div className='wea-edc-content'>
          {this.getContent()}
        </div>
      </div>
    );
  }

  getContent = () => {
    const { tabKey, readonly } = this.store;
    const { params } = this.props;

    return tabKey === 'form' ? <FormDesigner params={params} readonly={readonly} /> :
      tabKey === 'path' ? <PathDesigner params={params} readonly={readonly} /> :
        tabKey === 'excel' ? <EdcExcel params={params} readonly={readonly} /> :
          tabKey === 'analysis' ? <AnalysisDesigner params={params} readonly={readonly} /> : tabKey === 'data' ?
            <EdcData params={params} readonly={readonly}></EdcData> : null;
  }
}